<template>
  <div class="switch-agent">
      <div class="container">
          <div class="code-title text-overflow">切换代理商</div>
          <div class="form-info-box">
              <el-form class="form-info" :label-position="'top'" ref="ruleForm" :rules="rules" label-width="100px" :model="formInfo">
                <el-form-item label="被替换贴牌商手机号码" prop="fromAgent">
                <el-input v-model="formInfo.fromAgent"></el-input>
                </el-form-item>
                <el-form-item label="替换贴牌商手机号码:" prop="toAgent">
                <el-input v-model="formInfo.toAgent"></el-input>
                </el-form-item>
                <div class="tips">【注意】： 此操作会转移被替换贴牌商名下的所有台卡！请谨慎操作！</div>
                <el-form-item>
                <el-button size="large" type="primary" @click="submitForm('ruleForm')">提交</el-button>
                <el-button size="large" @click="resetForm('ruleForm')">重置</el-button>
                </el-form-item>
            </el-form>
          </div>
      </div>
    
  </div>
</template>

<script>
export default {
  name:'switch-agent',
  data () {
      const validatePhone = (rule, value, callback)=>{
       if (value === '' || value === null) {
         return callback(new Error('手机号不能为空'));
       } 
       setTimeout(() => {
          if(/^[1][1-9][0-9]{4,9}/.test(value)){
            callback()
          }else{
            return callback(new Error('手机格式不正确'));
          }
       },500); 
    }

    return {
        formInfo:{
           fromAgent:null,
           toAgent:null,
        },
        rules:{
           fromAgent:[
             { validator: validatePhone, trigger: 'blur' }
           ],
            toAgent:[
               { validator: validatePhone, trigger: 'blur' }
            ]
        }
    };
  },
  components: {},
  created() {},
  mounted() {},
  methods: {
    resetForm(formName) {
        this.$refs[formName].resetFields();
    },
    submitForm(){
        const token = sessionStorage.getItem(1);
        let url = `user/Platform/bmsUpdatePlatForm/${token}`;
        let params = `fromAgent=${this.formInfo.fromAgent}&toAgent=${this.formInfo.toAgent}`;
        this.$Http.post(url,params).then(res=>{
            if(res.data.resp_code === '000000'){
                this.$message.success('贴牌商更换成功！');
            }else{
                this.$message.info(res.data.resp_message)
            }
        }).catch(err=>{
            this.$notify.error({
                title: '错误',
                message: '服务器繁忙！更换失败！'
            });
        })
    }
  }
}

</script>
<style scoped>
.switch-agent{
    box-sizing: border-box;
  padding: 20px;
}
.form-info-box{
  border: 1px solid #ededed;
  padding: 20px;
}
.form-info{
  max-width: 600px;
  min-width: 250px;
  border: 1px solid #ededed;
  padding: 20px;
}
.add-member-title{
  height: 50px;
  line-height: 50px;
  font-size: 26px;
  color: #409eff;
  padding: 5px 20px;
  border: 1px solid #ededed;
}
.tips{
  padding: 20px;
  color: red;
  border-bottom: 1px solid #ededed;
  margin-bottom: 20px;
}
</style>